package com.heimao;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class HelloController {


    //query接受方式
    //http://localhost:8080/hello?a=1&b=2
    @RequestMapping("/hello")
    public String hello(int a,int b, Model model){
        int sum=a+b;
        model.addAttribute("msg","我是页面信息"+sum);
        return "hello";
    }

    //使用restFul风格的请求方式即：参数值作为路径的一部分
    //http://localhost:8080/test/2/3
    @RequestMapping(value="/test/{a}/{b}",method= RequestMethod.GET)
    public String test(@PathVariable int a,@PathVariable int b,Model model){
        int sum=a+b;
        model.addAttribute("msg","我是页面信息"+sum);
        return "hello";
    }

    @GetMapping("/test2/{a}/{b}")
    public String testGet(@PathVariable int a,@PathVariable int b,Model model){
        int sum=a+b;
        model.addAttribute("msg","我是页面信息"+sum);
        return "hello";
    }

    @PostMapping ("/test2/{a}/{b}")
    public String testPost(@PathVariable int a,@PathVariable int b,Model model){
        int sum=a+b;
        model.addAttribute("msg","我是页面信息"+sum);
        return "hello";
    }



}
